﻿#region

using System.Collections.Generic;
using Lab.Common.Dto;
using Lab.Server.Infrastructure;

#endregion

namespace Lab.Server.Application {
    public class ApplicationService {
        private readonly Context context;

        public ApplicationService(Context context) {
            this.context = context;
        }

        public void AddVacancy(DtoVacancy dtoVacancy) {
            var vacancy = Translator.TranslateToDomain(dtoVacancy);

            var repository = context.Get<VacancyRepository>();
            repository.Save(vacancy);
        }


        public void AddEmployer(DtoEmployer dtoEmployer) {
            var employer = Translator.TranslateToDomain(dtoEmployer);

            employer.Validate();

            var repository = context.Get<EmployerRepository>();
            repository.Save(employer);
        }

        public void AddKindOfActivity(DtoKindOfActivity dtoKindOfActivity) {
            var repository = context.Get<KindOfActivityRepository>();
            repository.Save(Translator.TranslateToDomain(dtoKindOfActivity));
        }

        public void AddSkill(DtoSkill dtoSkill) {
            var repository = context.Get<SkillRepository>();
            repository.Save(Translator.TranslateToDomain(dtoSkill));
        }

        public void AddApplicant(DtoApplicant dtoApplicant) {
            var applicant = Translator.TranslateToDomain(dtoApplicant);

            var repository = context.Get<ApplicantRepository>();
            repository.Save(applicant);
        }

        public void MakeDeal(DtoDeal dtoDeal) {
            var deal = Translator.TranslateToDomain(dtoDeal);

            var repository = context.Get<DealRepository>();
            repository.Save(deal);
        }

        public ICollection<DtoVacancy> GetOpenVacancies() {
            return context.Get<VacancyRepository>().GetOpenVacancies().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoSkill> GetSkills() {
            return context.Get<SkillRepository>().GetSkills().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoVacancy> GetAllVacancies() {
            return context.Get<VacancyRepository>().GetAllVacancies().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoEmployer> GetEmployers() {
            return context.Get<EmployerRepository>().GetEmployers().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoKindOfActivity> GetKindOfActivities() {
            return context.Get<KindOfActivityRepository>().GetKindOfActivities().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoApplicant> GetApplicants() {
            return context.Get<ApplicantRepository>().GetApplicants().ConvertAll(Translator.TranslateToDto);
        }

        public List<DtoDeal> GetDeals() {
            return context.Get<DealRepository>().GetDeals().ConvertAll(Translator.TranslateToDto);
        }
    }
}